//
//  SkipViewController.m
//  project_delicious
//
//  Created by dlios on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "SkipViewController.h"
#import "FoodTherapyCell.h"
#import "MaiTangCollectionViewController.h"
#import "SkipCell.h"

@interface SkipViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSString *sid;
@property (nonatomic, retain) MBProgressHUD *hud;
@end

@implementation SkipViewController
- (void)dealloc
{
    [_hud release];
    [_tableView release];
    [_arr release];
    [super dealloc];
}

- (NSURL *)strChangeUrl:(NSString *)str
{
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    return url;
}


- (void)dataHandler:(NSString *)str
{
//    self.navigationController.navigationBar.translucent = NO;
//    self.tabBarController.tabBar.hidden = YES;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.arr = [responseObject objectForKey:@"data"];
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain];
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        self.tableView.contentSize = CGSizeMake(0, self.arr.count * 44);
        [self.view addSubview:self.tableView ];
        self.tableView.backgroundColor = [UIColor clearColor];
        self.tableView.separatorColor = [UIColor clearColor];
        
        [_tableView release];
        [_tableView registerClass:[SkipCell class] forCellReuseIdentifier:@"guo"];
        [_hud removeFromSuperview];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"发生错误: %@", error);
    }];
    
    
    
}
//转菊花
- (void)mbHud
{
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    self.hud.labelText = @"Loading...";
    //self.hud.detailsLabelText = @"正在为您加载";
    [self.view addSubview:self.hud];
    [_hud release];
    [_hud show:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self mbHud];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IMG_1345.JPG"]];

        NSString *str = @"http://121.40.54.251:80/HandheldKitchen/api/more/hotwater!getHotwaterTypeList.do?is_traditional=0";
        [self dataHandler:str];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 66;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SkipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"guo"];
    NSString *cellName = [[self.arr objectAtIndex:indexPath.row] valueForKey:@"name"];
    cell.name = cellName;
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MaiTangCollectionViewController *collection = [[MaiTangCollectionViewController alloc] init];
    self.sid = [[self.arr objectAtIndex:indexPath.row] objectForKey:@"id"];
    NSInteger ss = [self.sid integerValue];
    NSString *str = [NSString stringWithFormat:@"http://121.40.54.251:80/HandheldKitchen/api/more/hotwater!getHotwaterList.do?id=%ld&page=1&pageRecord=10&is_traditional=0", ss];
    collection.str = str;
    collection.tid = ss;
    NSString *reStrP = [NSString stringWithFormat:@"http://121.40.54.251:80/HandheldKitchen/api/more/hotwater!getHotwaterList.do?id=%ld&page=", ss];
    NSString *reStrS = @"&pageRecord=10&is_traditional=0";
    collection.reStrP = reStrP;
    collection.reStrS = reStrS;
    
    [self.navigationController pushViewController:collection animated:YES];
    [collection release];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
